package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.CrmBanner;
import com.atguigu.eduservice.mapper.CrmBannerMapper;
import com.atguigu.eduservice.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author 李红磊
 * @since 2021-06-23
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    //查询所有banner
    @Override
    @Cacheable(key ="'selectIndexList'" ,value = "banner")
    public List<CrmBanner> selectAllBanner() {
        //查询所有banner
            //根据id降序排列，显示排列之后的前两条记录
            QueryWrapper<CrmBanner> bannerQueryWrapper = new QueryWrapper<>();
            bannerQueryWrapper.orderByDesc("id");
            //list拼接sql语句
            bannerQueryWrapper.last("limit 2");

            List<CrmBanner> list = baseMapper.selectList(bannerQueryWrapper);
            return list;
        }

}
